//
//  SchActivitiesSingeCell.m
//  AttendenceSys
//
//  Created by ld on 16/2/28.
//  Copyright © 2016年 窦芳俊. All rights reserved.
//

#import "SchActivitiesSingeCell.h"

@implementation SchActivitiesSingeCell

- (void)dealloc
{
    _headImageBtn = nil;
    _nameLab = nil;
    _timeLab = nil;
    _descLab = nil;
    _imageScrollView = nil;
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier])
    {
        [self initCell];
    }
    
    return self;
}

- (void)initCell
{
    self.selectionStyle = UITableViewCellSelectionStyleNone;
    
    _bgActView = [[UIView alloc] initWithFrame:CGRectMake(0, 10, [UIScreen mainScreen].bounds.size.width,singleCellHeight-10)];
    _bgActView.backgroundColor = [UIColor whiteColor];
    
    _headImageBtn = [[ASButton alloc] initWithFrame:CGRectMake(10, 10, 40, 40)];
    [_headImageBtn setBackgroundColor:[UIColor clearColor]];
    //[_headImageBtn setBackgroundImage:[UIImage imageNamed:@"portrait_1"] forState:UIControlStateNormal];
    //path = @"http://121.42.185.124:8080/LawSchool//temp/picture/original/IMG_20151021_091440.jpg";
//    ASNetworkEngine *networkingEngine = [ASNetworkEngine sharedInstance];
//    
//    [networkingEngine downLoadData: @"http://121.42.185.124:8080/LawSchool//temp/picture/original/IMG_20151021_091440.jpg" image:_headImageView];
    
    [_bgActView addSubview:_headImageBtn];
    
    _nameLab = [[UILabel alloc] initWithFrame:CGRectMake(_headImageBtn.frame.origin.x+55,
                                                         30,
                                                         [UIScreen mainScreen].bounds.size.width-150,
                                                         25)];
    [_nameLab setBackgroundColor:[UIColor clearColor]];
    _nameLab.center = _headImageBtn.center;
    CGRect frame = _nameLab.frame;
    frame.origin.x = _headImageBtn.frame.origin.x+55;
    frame.size.width = [UIScreen mainScreen].bounds.size.width-150;
    frame.size.height = 25;
    _nameLab.frame = frame;
    _nameLab.font = [UIFont systemFontOfSize:16];
    _nameLab.text = @"";
    [_nameLab setTextAlignment:NSTextAlignmentLeft];
    _nameLab.textColor = [UIColor blackColor];
    [_bgActView addSubview:_nameLab];
    
    _timeLab = [[UILabel alloc] initWithFrame:CGRectMake([UIScreen mainScreen].bounds.size.width-170,
                                                         _nameLab.frame.origin.y,
                                                         150,
                                                         20)];
    [_timeLab setBackgroundColor:[UIColor clearColor]];
    _timeLab.font = [UIFont systemFontOfSize:14];
    [_timeLab setTextAlignment:NSTextAlignmentRight];
    _timeLab.text = @"";
    _timeLab.textColor = [UIColor colorWithRed:102.0/255.0 green:102.0/255.0 blue:102.0/255.0 alpha:1.0f];
    [_bgActView addSubview:_timeLab];
    
    _actionTitleLab = [[UILabel alloc] initWithFrame:CGRectZero];
    [_actionTitleLab setBackgroundColor:[UIColor clearColor]];
    _actionTitleLab.font = [UIFont systemFontOfSize:15];
    _actionTitleLab.textColor = [UIColor colorWithRed:102.0/255.0 green:102.0/255.0 blue:102.0/255.0 alpha:1.0f];
    _actionTitleLab.numberOfLines = 0;
    _actionTitleLab.text = @"";
    [_actionTitleLab setTextAlignment:NSTextAlignmentLeft];
    
    // 调整行间距
    NSMutableAttributedString *attributedString1 = [[NSMutableAttributedString alloc] initWithString:_actionTitleLab.text];
    NSMutableParagraphStyle *paragraphStyle1 = [[NSMutableParagraphStyle alloc] init];
    [paragraphStyle1 setLineSpacing:6];
    [attributedString1 addAttribute:NSParagraphStyleAttributeName
                              value:paragraphStyle1
                              range:NSMakeRange(0, [_actionTitleLab.text length])];
    _actionTitleLab.attributedText = attributedString1;
    [_actionTitleLab sizeToFit];
    _actionTitleLab.lineBreakMode = NSLineBreakByTruncatingTail;
    _actionTitleLab.frame = CGRectMake(10, 60, [UIScreen mainScreen].bounds.size.width-20, 20);
    _actionTitleLab.textColor = [UIColor colorWithRed:102.0/255.0 green:102.0/255.0 blue:102.0/255.0 alpha:1.0f];
    [_bgActView addSubview:_actionTitleLab];
    
    _descLab = [[UILabel alloc] initWithFrame:CGRectZero];
    [_descLab setBackgroundColor:[UIColor clearColor]];
    _descLab.font = [UIFont systemFontOfSize:14];
    _descLab.textColor = [UIColor colorWithRed:102.0/255.0 green:102.0/255.0 blue:102.0/255.0 alpha:1.0f];
    _descLab.numberOfLines = 0;
    _descLab.text = @"";
    [_descLab setTextAlignment:NSTextAlignmentLeft];
    
    // 调整行间距
    NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:_descLab.text];
    NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
    [paragraphStyle setLineSpacing:6];
    [attributedString addAttribute:NSParagraphStyleAttributeName
                             value:paragraphStyle
                             range:NSMakeRange(0, [_descLab.text length])];
    //_descLab.attributedText = attributedString;
    //[_descLab sizeToFit];
    _descLab.lineBreakMode = NSLineBreakByTruncatingTail;
    _descLab.frame = CGRectMake(10,
                                _actionTitleLab.frame.size.height+60,
                                [UIScreen mainScreen].bounds.size.width-20,
                                50);
    _descLab.textColor = [UIColor blackColor];
    [_bgActView addSubview:_descLab];
    
    _attendLab = [[UILabel alloc] initWithFrame:CGRectMake(10, singleCellHeight-35, 150, 15)];
    [_attendLab setBackgroundColor:[UIColor clearColor]];
    _attendLab.font = [UIFont systemFontOfSize:14];
    [_attendLab setTextAlignment:NSTextAlignmentLeft];
    _attendLab.text = @"";
    _attendLab.textColor = [UIColor colorWithRed:102.0/255.0 green:102.0/255.0 blue:102.0/255.0 alpha:1.0f];
    [_bgActView addSubview:_attendLab];
    
    _scanSignLab = [[UILabel alloc] initWithFrame:CGRectMake([UIScreen mainScreen].bounds.size.width-10-150-10,
                                                             singleCellHeight-35,
                                                             150,
                                                             15)];
    [_scanSignLab setBackgroundColor:[UIColor clearColor]];
    _scanSignLab.font = [UIFont systemFontOfSize:14];
    [_scanSignLab setTextAlignment:NSTextAlignmentRight];
    _scanSignLab.text = @"";
    _scanSignLab.textColor = [UIColor colorWithRed:102.0/255.0 green:102.0/255.0 blue:102.0/255.0 alpha:1.0f];
    [_bgActView addSubview:_scanSignLab];
    
    [self.contentView addSubview:_bgActView];
}

- (void)updateDescLabelStatus:(BOOL)havePic
{
    _descLab.frame = CGRectMake(10,
                                _actionTitleLab.frame.size.height+60,
                                [UIScreen mainScreen].bounds.size.width-20,
                                havePic ? 50 : singleCellHeight-35-(_actionTitleLab.frame.size.height+60));
}

- (void)initScrollView:(NSMutableArray*)arrUrl
{
    [_imageScrollView removeFromSuperview];
    if (_imageScrollView)
    {
        _imageScrollView = nil;
    }
    
    if ([arrUrl count] <= 0)
    {
        return;
    }
    
    if (nil == _imageScrollView)
    {
        _imageScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0,
                                                                          _descLab.frame.origin.y+50+4,
                                                                          [UIScreen mainScreen].bounds.size.width,
                                                                          singleCellHeight-_descLab.frame.origin.y-50-4)];
        _imageScrollView.directionalLockEnabled = YES; //只能一个方向滑动
        _imageScrollView.pagingEnabled = YES; //是否翻页
        _imageScrollView.backgroundColor = [UIColor clearColor];
        _imageScrollView.showsVerticalScrollIndicator = NO; //垂直方向的滚动指示
        _imageScrollView.indicatorStyle = UIScrollViewIndicatorStyleWhite;//滚动指示的风格
        _imageScrollView.showsHorizontalScrollIndicator = YES;//水平方向的滚动指示
        _imageScrollView.userInteractionEnabled = YES;
        _imageScrollView.delegate = self;
        [_bgActView addSubview:_imageScrollView];
    }
    
    //设置滚动视图的位置
    [_imageScrollView setContentSize:CGSizeMake(([UIScreen mainScreen].bounds.size.width/3*arrUrl.count),
                                                _imageScrollView.frame.size.height)];
    
    for (unsigned int i = 0; i < [arrUrl count]; i++)
    {
        NSString* url = [arrUrl objectAtIndex:i];
        
        ASButton* imageBtnView = [[ASButton alloc] initWithFrame:CGRectMake(10*(i+1) + i*([UIScreen mainScreen].bounds.size.width-40)/3, 0, ([UIScreen mainScreen].bounds.size.width-40)/3, ([UIScreen mainScreen].bounds.size.width-40)/3)];
        [imageBtnView setBackgroundColor:[UIColor clearColor]];
        imageBtnView.contentMode = UIViewContentModeScaleAspectFill;
        imageBtnView.userInteractionEnabled = YES;
        //UIViewContentModeScaleAspectFit
        
        [imageBtnView setImageWithURL:url placeholderImage:[UIImage imageNamed:@"portrait_default"]];

        [_imageScrollView addSubview:imageBtnView];
    }
}

- (void)initActDetailInfoView
{
    _bgActDetailView = [[UIView alloc] initWithFrame:CGRectMake(0,
                                                                singleCellHeight+5,
                                                                [UIScreen mainScreen].bounds.size.width,
                                                                singleCellHeight*5-5)];
    _bgActDetailView.backgroundColor = [UIColor whiteColor];
    
    _detailTime = [[UILabel alloc] initWithFrame:CGRectMake(20, 10, [UIScreen mainScreen].bounds.size.width-20, 20)];
    _detailTime.font = [UIFont systemFontOfSize:14];
    _detailTime.text = @"";
    [_detailTime setTextAlignment:NSTextAlignmentLeft];
    _detailTime.textColor = [UIColor colorWithRed:102.0/255.0 green:102.0/255.0 blue:102.0/255.0 alpha:1.0];
    [_bgActDetailView addSubview:_detailTime];
    
    _sponsorLab = [[UILabel alloc] initWithFrame:CGRectMake(_detailTime.frame.origin.x,
                                                            _detailTime.frame.origin.y+_detailTime.frame.size.height+8,
                                                            _detailTime.frame.size.width,
                                                            20)];
    [_sponsorLab setBackgroundColor:[UIColor clearColor]];
    _sponsorLab.font = [UIFont systemFontOfSize:14];
    [_sponsorLab setTextAlignment:NSTextAlignmentLeft];
    _sponsorLab.text = @"";
    _sponsorLab.textColor = [UIColor colorWithRed:102.0/255.0 green:102.0/255.0 blue:102.0/255.0 alpha:1.0f];
    [_bgActDetailView addSubview:_sponsorLab];
    
    _areaLab = [[UILabel alloc] initWithFrame:CGRectMake(_sponsorLab.frame.origin.x,
                                                         _sponsorLab.frame.origin.y+_detailTime.frame.size.height+8,
                                                         _sponsorLab.frame.size.width,
                                                         20)];
    [_areaLab setBackgroundColor:[UIColor clearColor]];
    _areaLab.font = [UIFont systemFontOfSize:14];
    _areaLab.textColor = [UIColor colorWithRed:102.0/255.0 green:102.0/255.0 blue:102.0/255.0 alpha:1.0f];
    _areaLab.text = @"";
    [_areaLab setTextAlignment:NSTextAlignmentLeft];
    [_bgActDetailView addSubview:_areaLab];
    
    UIImageView* lineView = [[UIImageView alloc] initWithFrame:CGRectMake(0,
                                                                          _areaLab.frame.origin.y+_areaLab.frame.size.height+10-1,
                                                                          [UIScreen mainScreen].bounds.size.width,
                                                                          1)];
    [lineView setBackgroundColor:RGB(240, 240, 240)];
    [_bgActDetailView addSubview:lineView];
    
//    _voteNumLab = [[UILabel alloc] initWithFrame:CGRectMake(15, lineView.frame.origin.y+lineView.frame.size.height+5, _sponsorLab.frame.size.width-15, 20)];
//    [_voteNumLab setBackgroundColor:[UIColor clearColor]];
//    _voteNumLab.font = [UIFont systemFontOfSize:14];
//    _voteNumLab.textColor = [UIColor colorWithRed:102.0/255.0 green:102.0/255.0 blue:102.0/255.0 alpha:1.0f];
//    _voteNumLab.text = @"";
//    [_voteNumLab setTextAlignment:NSTextAlignmentLeft];
//    [_bgActDetailView addSubview:_voteNumLab];
    
    [self.contentView addSubview:_bgActDetailView];
}

- (void)initfavHeadScrollView:(NSMutableArray*)favHeadUrl
{
    if (nil == _favHeadSclView)
    {
        _favHeadSclView = [[UIScrollView alloc] initWithFrame:CGRectMake(0,
                                                                         _voteNumLab.frame.origin.y+22.5,
                                                                         [UIScreen mainScreen].bounds.size.width,
                                                                         _bgActDetailView.frame.size.height-_voteNumLab.frame.origin.y-20)];
        _favHeadSclView.directionalLockEnabled = YES; //只能一个方向滑动
        _favHeadSclView.pagingEnabled = YES; //是否翻页
        _favHeadSclView.backgroundColor = [UIColor clearColor];
        _favHeadSclView.showsVerticalScrollIndicator = NO; //垂直方向的滚动指示
        _favHeadSclView.indicatorStyle = UIScrollViewIndicatorStyleWhite;//滚动指示的风格
        _favHeadSclView.showsHorizontalScrollIndicator = YES;//水平方向的滚动指示
        _favHeadSclView.userInteractionEnabled = YES;
        _favHeadSclView.delegate = self;
        [_bgActDetailView addSubview:_favHeadSclView];
    }
    //设置滚动视图的位置
    [_favHeadSclView setContentSize:CGSizeMake([UIScreen mainScreen].bounds.size.width*(favHeadUrl.count/10),
                                               _favHeadSclView.frame.size.height)];
    
    for (unsigned int i = 0; i < [favHeadUrl count]; i++)
    {
        UIImageView* headImageView = [[UIImageView alloc] initWithFrame:CGRectMake((i+1)*([UIScreen mainScreen].bounds.size.width-25*10)/11+25*i, 0, 25, 25)];
        [headImageView setBackgroundColor:[UIColor clearColor]];
        [headImageView setImage:[UIImage imageNamed:@"portrait_1"]];
        [headImageView setBackgroundColor:[UIColor clearColor]];
        headImageView.contentMode = UIViewContentModeScaleAspectFit;
        [_favHeadSclView addSubview:headImageView];
    }
    
    [_bgActDetailView addSubview:_favHeadSclView];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];
}

@end




